package cn.jingyinghui.rules.person;// cn.jingyinghui.rules.person.DroolsTest.java
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

/**
 * 测试一个人能否购买成年人衣服
 */
public class ClothesDroolTest {
    public static void main(String[] args) {
        try {
            // 加载KieServices，读取配置
//            KieServices kieServices = KieServices.Factory.get();
            KieServices kieServices = KieServices.get();

            // 获取KieContainer，它包含了所有定义好的规则
            KieContainer kieContainer = kieServices.getKieClasspathContainer();

            //打印可用的kieContainer
            KieBase kieBase = kieContainer.getKieBase("defaultKieBase");
            System.out.println("Rules loaded: " + kieBase.getKiePackages());
            
            // 创建KieSession，用于执行规则
            KieSession kieSession = kieContainer.newKieSession("clothesSession");

            // 创建一个Person对象并插入到KieSession中
            Person person = new Person("Alice", 20);
            kieSession.insert(person);

            // 执行规则
            kieSession.fireAllRules();

            // 关闭KieSession
            kieSession.dispose();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
